<?php
namespace MobileHome\Controller;

class IndexController extends BaseController
{
    public function indexAction()
    {
        vendor('Wechat.Jssdk', '', '.class.php');
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $cachePath = RUNTIME_PATH;
        $jssdk = new \JSSDK(C('WECHAT.AppID'), C('WECHAT.AppSecret'), $url, $cachePath);
        $signPackage = $jssdk->GetSignPackage();
        $jsApiList = ['onMenuShareTimeline', 'onMenuShareAppMessage', 'chooseImage', 'uploadImage'];
        $config = [
            'debug'     => false,
            'appId'     => C('WECHAT.AppID'),
            'timestamp' => $signPackage['timestamp'],
            'nonceStr'  => $signPackage['nonceStr'],
            'signature' => $signPackage['signature'],
            'jsApiList' => $jsApiList,
        ];
        $this->assign('jssdk_config', $config);
        $this->display();
    }
}